Alrighty, in this lecture we're going to be implementing animations for our zombies.
We're going to need an animation for when our zombies are walking around, when they're standing still
in an idle state when they're running.
And we'll also need some animations for when our zombies try to attack a player.
Now, I'm not the best at creating animations, but I did create animations for my zombies.
So let me open up my animation editor.
And as you can see, I've created several animations.
One for when my zombie is walking.
I created an animation for when my zombie is running.
I've created an animation for an idle state for my zombie, as well as a second idle state.
And then I've created some attack animations when the zombie is swinging at a player.
I encourage you to create your own animations as well, but if you would like to use my animations or
make some adjustments and modifications to my animations, then I will have this rig attached to the
lecture for you to upload the animations to your Roblox account.
Now, the easiest way for us to implement these animations into our zombie would be to copy the script
Roblox already uses for animating character models.
We can grab this script by generating a new AR 15 rig, so we'll go to Rig Builder.
We'll make a new block rig avatar, and inside of this rig we're going to find an animate script.
So what we can go ahead and do is open up this local script and copy all of the code inside of it,
and place it inside of a server script.
So what I'm going to do is I'm going to grab one of my zombies from server storage.
I'll grab my regular zombie and place them inside of the workspace, and then we can go ahead and create
a new server script inside of him.
I'm going to call it the animate script, and they're just going to paste all of that code inside of
there.
And then we're also going to go ahead and copy all of the descendants of that local script.
So we're going to go in here, copy that, and then paste it inside of our animate script as well.
And to make this script work on the server, there's a small section that we're going to need to remove.
That's for some client sided stuff.
So yeah, it's right here at line 757.
It's attempting to grab the local player and listen to the chatted event, but since this is inside
of a server script, there is no local player, so we can just go ahead and delete that section.
And now this code should work on our zombie, but for the server.
Then what we can go ahead and do is we can grab all of the animation IDs that we've uploaded and paste
them into their respective animation instances.
So for example, with our Idalene animations, we can take the first one and paste its id into this
animation id property.
And then we can do the same for the second idalene animation.
And then for the running animation, we can paste it into this animation instance.
And for the walking animation we can paste it inside of this walk animation instance.
So I've gone ahead and pasted in my animations for each one of these animation instances, and then
to implement the attack animations, we can go ahead and go back to the zombie AI server script for
our zombies.
And inside of here is where we could play an attack animation when the zombie has this attack function
called.
So that means we're going to have to go into the properties module script for our zombies and insert
those two attack animations that we've uploaded, and place them inside of our attack animation IDs
table.
So I've gone ahead and pasted in my attack animation IDs inside my attack animation IDs table, and
now we can head back to our zombie AI server script, and we're going to go ahead and make a reference
to the animator instance that is inside of the humanoid of our zombie.
So we'll create a new variable, we'll call it the animator, and it's going to be equal to my humanoid
dot.
And we're going to get the animator.
Then what we can go ahead and do is inside of our attack function.
When we're attacking a player, we can go ahead and create and play a random attack animation.
So I'm going to create a new attack animation instance here.
So I'll just call it attack Anim.
And that's equal to instance dot new.
Create a new animation.
Now we can go ahead and set the animation ID equal to one of the random IDs inside of our attack animation
IDs table, so that'll be equal to properties dot attack animation IDs.
And then we're going to use RNG to pick a random one.
So next integer one to the number of elements inside of that table.
And then once we get that animation, we can go ahead and get the track by loading it.
So we'll refer to our animator and load the animation and pass our track animation.
And then we can go ahead and play that track.
And then when that track has ended, we'll connect a function to that event and we'll go ahead and clean
up our attack animation instance.
So we'll destroy that.
And then we'll also destroy the attack animation track.
So now we should have all the animations implemented for our zombies.
What we can go ahead and do is copy this new service script that we've just updated, and paste that
inside of each one of the zombies in our game, and delete the old zombie AI script.
And then we can also go ahead and grab our animate script and copy that, and then also put it inside
of each one of our zombie instances.
So we'll just go in through here and we'll paste that script inside of each one of our zombies.
And now every single zombie in our game should be animated, and they should play an attack animation
when they are trying to attack a player.
So let's go ahead and let's grab each one of these zombies and place them inside of the workspace in
the zombies folder.
So here's all of the zombies in our game.
I'm going to go ahead and clean up these two guys.
So I'm going to get rid of this guy and set this guy aside.
And now let's go ahead and run our game to see if they have the different animations, um, playing
on the zombies.
So if we run our game.
As you can see now, each one of our zombies are animated, so when they walk around they play their
walking animation.
Or if they're running fast enough, like this guy is, then they're playing the running animation.
Uh, and so far everything looks fine with how these guys are animated.
So now what we need to do is spawn a player into the game and see if they play their attack animations
when they try to attack us.
So let's go ahead and playtest our game.
Let's have one of these guys run after us.
So here comes all the zombies.
And let's go ahead and see if they play the attack animation.
So there you go.
As you can see, they're playing the attack animation and they're dealing damage to me.
So just like that, we've easily added animations to our zombies.
I'll see you in the next lecture.